package com.aiyige.page.publish.editbanner.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.aiyige.R;
import com.aiyige.page.publish.coursedescription.model.CourseCover;
import com.aiyige.utils.GlideUtil;
import com.aiyige.utils.StringUtils;
import com.aiyige.utils.widget.LabelImageView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class EditBannerAdapter extends BaseQuickAdapter<CourseCover, EditBannerAdapter.VH> {


    public EditBannerAdapter() {
        super(R.layout.edit_banner_item, new LinkedList<CourseCover>());
    }

    @Override
    protected void convert(VH helper, CourseCover item) {
        helper.bindData(item);
    }

    public class VH extends BaseViewHolder {
        CourseCover data;
        @BindView(R.id.coverIv)
        LabelImageView coverIv;
        @BindView(R.id.playIv)
        ImageView playIv;
        @BindView(R.id.addLayout)
        LinearLayout addLayout;

        public VH(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(CourseCover item) {
            data = item;
            switch (item.getType()) {
                case CourseCover.TYPE_ADD:
                    playIv.setVisibility(View.INVISIBLE);
                    coverIv.setVisibility(View.INVISIBLE);
                    addLayout.setVisibility(View.VISIBLE);
                    break;
                case CourseCover.TYPE_NORMAL: {
                    addLayout.setVisibility(View.INVISIBLE);
                    coverIv.setVisibility(View.VISIBLE);
                    GlideUtil.with(itemView.getContext())
                            .asGif()
                            .loadCover(data.getImageUrl())
                            .into(coverIv.getImageView());
                    switch (item.getMediaType()) {
                        case CourseCover.MEDIA_TYPE_PHOTO:
                            playIv.setVisibility(View.INVISIBLE);
                            if (data.isDefaultCover()) {
                                coverIv.setLabel(StringUtils.getString(R.string.cover));
                            } else {
                                coverIv.setLabel("");
                            }
                            break;
                        case CourseCover.MEDIA_TYPE_VIDEO:
                            playIv.setVisibility(View.VISIBLE);
                            coverIv.setLabel("");
                            break;
                    }
                    break;
                }
            }
        }
    }
}
